/*
 *  Created at 2011-12-06 21:23 GMT-03:00
 *  Author: Victor Williams Stafusa da Silva
 *  JSmartUnit
 */
package org.jsmartunit.invocations;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

import org.jsmartunit.model.ClassStructure;
import org.jsmartunit.model.TestRunner;
import org.jsmartunit.util.CollectionUtils;

import org.junit.runners.model.InitializationError;

/**
 * @author Victor Williams Stafusa da Silva
 */
public class StaticMethodInvocation implements Invocation {

    private final Method method;
    private final Object[] args;

    public StaticMethodInvocation(Method method, Object[] args) {
        if (method == null) throw new IllegalArgumentException();
        if (args == null) throw new IllegalArgumentException();
        if (!Modifier.isStatic(method.getModifiers())) throw new IllegalArgumentException();

        Class<?>[] formalParams = method.getParameterTypes();
        CollectionUtils.assertMatches(formalParams, args);

        this.method = method;
        this.args = args;
    }

    public Object invokeExplosively() throws Throwable {
        return ClassStructure.invokeExplosively(null, method, args);
    }

    public TestRunner createRunner(TestRunner parentRunner, String name) throws InitializationError {
        throw new UnsupportedOperationException();
    }
}
